﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace 线程Yield的使用
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread[] th = new Thread[6];

            for (int index = 0; index < th.Length; index++) {
                th[index] = new Thread(ThreadFun);
                th[index].IsBackground = true;
                th[index].Start(index.ToString());
            }

            while (true) { Thread.Yield(); }
        }

        static void ThreadFun(object obj) {
            string str = obj as string;
            DateTime dt ;
            uint count = 0;
            while (true) {
                count++;
                dt = DateTime.Now;
                Debug.Print("Thread:" + str + " --> count:" + count.ToString() + "  " + dt.ToString("yyyy-MM-dd HH:mm:ss:fff") + "\r\n");
                //Thread.Yield();
            }
        }
    }
}
